package com.ss.android.article.base.feature.feed.vh;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextPaint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.feed.activity.InfoLayout;
import com.ss.android.article.base.feature.feed.k;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.newmedia.a.TimeFormatter;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public abstract class af extends BaseFeedViewHolder implements k {
    private AtomicBoolean o;
    private boolean p;
    private View.OnClickListener q;
    protected int r;
    final View.OnClickListener popIconClickListener;
    final View.OnClickListener moreActionClickListener;

    public af(Context context,
              NetworkStatusMonitor networkStatusMonitor,
              FeedItemBehavior feedItemBehavior,
              ArticleActionHelper articleActionHelper,
              int feedType,
              TimeFormatter timeFormatter,
              int actualItemImageWidth,
              int actualItemImageHeight,
              int actualLargeImageWidth,
              int maxLargeImageHeight,
              int arg25,
              AtomicBoolean arg26) {
        this(context, networkStatusMonitor, feedItemBehavior, articleActionHelper, feedType,
                timeFormatter, actualItemImageWidth, actualItemImageHeight, actualLargeImageWidth, maxLargeImageHeight, arg25, arg26, (byte) 0);
    }

    private af(final Context context,
               NetworkStatusMonitor networkStatusMonitor,
               FeedItemBehavior feedItemBehavior,
               ArticleActionHelper articleActionHelper,
               int feedType,
               TimeFormatter timeFormatter,
               int actualItemImageWidth,
               int actualItemImageHeight,
               int actualLargeImageWidth,
               int maxLargeImageHeight,
               int arg12,
               AtomicBoolean arg13,
               byte arg14) {
        super(context, networkStatusMonitor, feedItemBehavior,
                articleActionHelper,
                feedType,
                timeFormatter,
                actualItemImageWidth,
                actualItemImageHeight, actualLargeImageWidth, maxLargeImageHeight);
        this.popIconClickListener = new View.OnClickListener() {

            public final void onClick(View view) {
                mFeedItemBehavior.handlePopIconClick(mPosition, view, o());
            }
        };
        this.moreActionClickListener = new View.OnClickListener() {

            public final void onClick(View view) {
                mFeedItemBehavior.handleMoreActionClick(mPosition, view, new Object[0]);
            }
        };
        this.q = new View.OnClickListener() {

            public final void onClick(View view) {
                BaseFeedViewHolder.a(context, mCellRef);
                a(view);
            }
        };
        this.r = arg12;
        this.o = arg13;
    }

    protected abstract void a(View arg1);

    protected final void a(View arg4, int arg5) {
        if (arg4 != null) {
            ViewGroup.LayoutParams v0 = arg4.getLayoutParams();
            ((ViewGroup.MarginLayoutParams) v0).rightMargin = this.resources.getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.right_image_ad_info_layout_right_margin);
            if (arg5 == 2) {
                ((ViewGroup.MarginLayoutParams) v0).rightMargin = this.resources.getDimensionPixelOffset(com.ss.android.article.browser.R.dimen.fh);
            }
        }
    }

    protected final void a(InfoLayout.Info arg3) {
        String v0 = this.n();
        if (!android.support.design.a.isTextEmpty(v0)) {
            arg3.a |= 32;
            arg3.c = v0;
            int v0_1 = this.mCellRef == null ? 3 : this.mCellRef.labelStyle;
            arg3.labelStyle = v0_1;
        }
    }

    protected final void a(ImageInfo imageInfo) {
        Object v1;
        List v6;
        int v5 = 8;
        int v9 = 2;
        ImageInfo v4 = null;
        if (imageInfo != null) {
            boolean v2 = this.o != null ? this.o.get() : false;
            switch (this.m()) {
                case 2: {
                    label_22:
                    if (this.mLargeImage == null) {
                        return;
                    }

                    this.l_();
                    if (!v2) {
                        this.p = false;
                        this.c(imageInfo);
                        return;
                    }

                    this.p = true;
                    ArticleHelper.setVisible(this.mLargeImage, imageInfo);
                    return;
                }
                case 3: {
                    label_37:
                    if (this.mImage3ImageViews == null) {
                        UIUtils.setVisibility(this.mImage3ImageContainerView, v5);
                        return;
                    }

                    if (this.mCellRef.cellType == 10) {
                        if (this.mCellRef.downloadAppAd == null) {
                            v6 = ((List) v4);
                        } else if (this.mCellRef.downloadAppAd.imageList != null) {
                            v6 = this.mCellRef.downloadAppAd.imageList;
                        } else {
                            v6 = ((List) v4);
                        }
                    } else if (this.mCellRef.cellType != 0 || this.mCellRef.Q != 3 || this.mCellRef.article == null) {
                        v6 = ((List) v4);
                    } else if (this.mCellRef.article.imageList != null) {
                        v6 = this.mCellRef.article.imageList;
                    } else {
                        v6 = ((List) v4);
                    }

                    if (v6 == null) {
                        UIUtils.setVisibility(this.mImage3ImageContainerView, v5);
                        return;
                    }

                    UIUtils.setVisibility(this.mImage3ImageContainerView, 0);
                    int v7 = v6.size();
                    Object v0 = v6.get(0);
                    Object v5_1 = v0 == null || v7 <= 1 ? v4 : v6.get(1);
                    if (v5_1 == null || v7 <= v9) {
                        v1 = v4;
                    } else {
                        v1 = v6.get(v9);
                    }

                    ArticleHelper.setVisible(this.mImage3FirstImageView, ((ImageInfo) v0));
                    ArticleHelper.setVisible(this.mImage3SecondImageView, ((ImageInfo) v5_1));
                    ArticleHelper.setVisible(this.mImage3ThirdImageView, ((ImageInfo) v1));
                    if (!v2) {
                        this.loadImage();
                        this.p = false;
                        return;
                    }

                    this.p = true;
                    return;
                }
                case 1:
                case 4: {
                    label_15:
                    if (this.mRightImageAdImage == null) {
                        return;
                    }

                    this.j();
                    if (!v2) {
                        this.p = false;
                        this.b(imageInfo);
                        return;
                    }

                    this.p = true;
                    ArticleHelper.setVisible(this.mRightImageAdImage, imageInfo);
                    return;
                }
            }

            return;
        }
    }

    protected final void a(String arg9, int arg10) {
        int v4 = 8;
        boolean v0 = true;
        TextView v2 = null;
        switch (arg10) {
            case 2: {
                v2 = this.mImage3Title;
                break;
            }
            case 3: {
                v2 = this.mImage3Title;
                break;
            }
            case 1:
            case 4: {
                v2 = this.mRightImageAdTitle;
                UIUtils.setVisibility(this.mImage3Title, v4);
                break;
            }
        }

        if (v2 != null) {
            if (android.support.design.a.isTextEmpty(arg9)) {
                UIUtils.setVisibility(((View) v2), v4);
            } else {
                if (this.mCellRef.j()) {
                    v2.setTextSize(18f);
                    TextPaint v3 = this.mImage3Title.getPaint();
                    if (this.mAppData.getAbSettings().isTitleBold()) {
                        v3.setFakeBoldText(true);
                        v2.setLineSpacing(UIUtils.dp2px(this.context, 2f), 1f);
                    } else {
                        v3.setFakeBoldText(false);
                    }
                } else {
                    v2.getPaint().setFakeBoldText(false);
                }

                UIUtils.setVisibility(((View) v2), 0);
                v2.setText(arg9);
                if (this.mCellRef == null) {
                    return;
                }

                if (this.mCellRef.readTs > 0) {
                    v0 = false;
                }

                v2.setEnabled(v0);
            }
        }
    }

    protected void a_(InfoLayout.Info arg1) {
    }

    static boolean b(int arg1, String arg2) {
        if (arg1 == 3 || arg1 == 4 || arg1 == 2) {
            if (!android.support.design.a.isTextEmpty(arg2) && !android.support.design.a.isTextEmpty(arg2.trim())) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

    protected void b(ImageInfo imageInfo) {
        if (imageInfo != null && (imageInfo.isValid()) && this.mRightImageAdImage != null) {
            UIUtils.setVisibility(this.mRightImageAdImageTagIcon, View.GONE);
            android.support.design.a.setImage(this.mRightImageAdImage, imageInfo);
            this.mRightImageAdImage.setTag(com.ss.android.article.browser.R.id.image_info, null);
        }
    }

    protected final void b(InfoLayout.Info info) {
        this.c(info);
        this.a_(info);
        this.h(info);
        this.g(info);
    }

    private void c(ImageInfo arg4) {
        if (arg4 != null && (arg4.isValid()) && this.mLargeImage != null) {
            android.support.design.a.setImage(this.mLargeImage, arg4);
            this.mLargeImage.setTag(com.ss.android.article.browser.R.id.image_info, null);
        }
    }

    protected final void c(int arg3) {
        AdLayoutHolder v0 = null;
        switch (arg3) {
            case 1: {
                v0 = this.mRightImageAdLayoutHolder;
                break;
            }
            case 2: {
                v0 = this.mLargeImageAdInfoAdLayoutHolder;
                break;
            }
            case 3:
            case 4: {
                v0 = this.mCreativityAdInfoLayoutHolder;
                break;
            }
        }

        if (v0 != null) {
            this.mAdActionBtnLayout = v0.mAdActionBtnLayout;
            this.mActionAdIcon = v0.mActionAdIcon;
            this.mActionAdTv = v0.mActionAdTv;
            this.mActionAdProgress = v0.mActionAdProgress;
            this.mActionAdInfoLayout = v0.mActionAdInfoLayout;
            this.mAppAdInfoLayout = v0.mAppAdInfoLayout;
            this.mAdNameTv = v0.mAdNameTv;
            this.mActionAdDivider = v0.mActionAdDivider;
            this.mAdDetailInfoTv = v0.mAdDetailInfoTv;
            this.mAdDownloadProgressLayout = v0.mAdDownloadProgressLayout;
            this.mAdDownloadSize = v0.mAdDownloadSize;
            this.mAdDownloadStatus = v0.mAdDownloadStatus;
            this.mAdDownloadProgress = v0.mAdDownloadProgress;
            this.mLbsAdInfoLayout = v0.mLbsAdInfoLayout;
            this.mLbsAdAddressInfoTv = v0.mLbsAdAddressInfoTv;
            this.mLbsAdCurrentPriceTv = v0.mLbsAdCurrentPriceTv;
            this.mLbsAdOriginPriceTv = v0.mLbsAdOriginPriceTv;
            this.mLbsAdSoldNumberTv = v0.mLbsAdSoldNumberTv;
        }
    }

    public final boolean d() {
        return this.p;
    }

    public final void e() {
        this.p = false;
    }

    public final void loadImage() {
        switch (this.m()) {
            case 2: {
                this.c(ArticleHelper.getImageInfoTag(this.mLargeImage));
                break;
            }
            case 3: {
                if (this.mImage3ImageContainerView == null) {
                    return;
                }

                if (this.mImage3ImageContainerView.getVisibility() != View.VISIBLE) {
                    return;
                }

                if (this.mImage3ImageViews == null) {
                    return;
                }

                int v0;
                for (v0 = 0; v0 < 3; ++v0) {
                    ImageInfo v1 = ArticleHelper.getImageInfoTag(this.mImage3ImageViews[v0]);
                    if (v1 != null) {
                        android.support.design.a.setImage(this.mImage3ImageViews[v0], v1);
                        this.mImage3ImageViews[v0].setTag(com.ss.android.article.browser.R.id.image_info, null);
                    }
                }
            }
            case 1:
            case 4: {
                this.b(ArticleHelper.getImageInfoTag(this.mRightImageAdImage));
                break;
            }
        }
    }

    protected abstract void j();

    public void onMovedToScrapHeap() {
        int v2 = com.ss.android.article.browser.R.id.image_info;
        View.OnClickListener v3 = null;
        int v4 = View.GONE;
        super.onMovedToScrapHeap();
        a(this.duplicatePressedRelativeLayout, v3);
        a(this.mLargeImageLayout, v3);
        switch (this.m()) {
            case 2: {
                if (this.mLargeImage == null) {
                    break;
                }

                this.mLargeImage.setTag(v2, v3);
                break;
            }
            case 3: {
                UIUtils.setVisibility(this.mImage3ImageContainerView, View.GONE);
                if (this.mImage3ImageContainerView == null) {
                    break;
                }

                if (this.mImage3ImageContainerView.getVisibility() != View.VISIBLE) {
                    break;
                }

                if (this.mImage3ImageViews == null) {
                    break;
                }

                int v0;
                for (v0 = 0; v0 < 3; ++v0) {
                    android.support.design.a.removeImageInfoTag(this.mImage3ImageViews[v0]);
                    if (this.mImage3ImageViews[v0] != null) {
                        this.mImage3ImageViews[v0].setImageDrawable(((Drawable) v3));
                    }
                }
            }
            case 1:
            case 4: {
                if (this.mRightImageAdImage == null) {
                } else {
                    this.mRightImageAdImage.setTag(v2, v3);
                }
                break;
            }
        }

        if (this.mImage3InfoLayout != null) {
            this.mImage3InfoLayout.b();
            this.mImage3InfoLayout.setVisibility(View.GONE);
        }

        if (this.mRightInfoLayoutGroup != null) {
            this.mRightInfoLayoutGroup.b();
            this.mRightInfoLayoutGroup.setVisibility(View.GONE);
        }

        if (this.mNewInfoLayout != null) {
            this.mNewInfoLayout.b();
            this.mNewInfoLayout.setVisibility(View.GONE);
        }

        if (this.mRightImageAdInfoLayout != null) {
            ViewGroup.LayoutParams v0_1 = this.mRightImageAdInfoLayout.getLayoutParams();
            if (Build.VERSION.SDK_INT >= 17) {
                ((RelativeLayout.LayoutParams) v0_1).removeRule(15);
            }

            this.mRightImageAdInfoLayout.setLayoutParams(v0_1);
        }

        if (this.mImage3Title != null) {
            this.mImage3Title.setText("");
        }

        if (this.mRightImageAdTitle != null) {
            this.mRightImageAdTitle.setText("");
        }

        UIUtils.setVisibility(this.mRightImageAdTitle, View.GONE);
        UIUtils.setVisibility(this.mImage3Title, View.VISIBLE);
        UIUtils.setVisibility(this.mLargeImageLayout, View.GONE);
        UIUtils.setVisibility(this.mLargeImageAdInfoLayout, View.GONE);
        UIUtils.setVisibility(this.mRightImageAdLayout, View.GONE);
        UIUtils.setVisibility(this.mRightImageAdCreativityLayout, View.GONE);
        UIUtils.setVisibility(this.mImage3ImageContainer, View.GONE);
        UIUtils.setVisibility(this.mImage3ImageContainerView, View.GONE);
        UIUtils.setVisibility(this.mLargeImageAdInfoLayout_AdInfoLayout, View.GONE);
        UIUtils.setVisibility(this.mRightImageAdLayout_AdInfoLayout, View.GONE);
        UIUtils.setVisibility(this.mCreativityAdInfoLayout, View.GONE);
    }

    protected void l() {
        a(this.duplicatePressedRelativeLayout, this.q);
    }

    protected abstract void l_();

    protected abstract int m();

    protected abstract String n();

    protected abstract int o();

    protected final void t() {
        switch (this.m()) {
            case 1: {
                UIUtils.setVisibility(this.mImage3InfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mRightImageAdLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mRightImageAdLayout_AdInfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mRightInfoLayoutGroup, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdCreativityLayout, View.GONE);
                UIUtils.setVisibility(this.mCreativityAdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mImage3ImageContainer, View.GONE);
                break;
            }
            case 2: {
                UIUtils.setVisibility(this.mRightImageAdLayout, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mImage3InfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mLargeImageLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout_AdInfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mRightInfoLayoutGroup, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdCreativityLayout, View.GONE);
                UIUtils.setVisibility(this.mCreativityAdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mImage3ImageContainer, View.GONE);
                break;
            }
            case 3: {
                UIUtils.setVisibility(this.mRightImageAdLayout, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mRightInfoLayoutGroup, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdCreativityLayout, View.GONE);
                UIUtils.setVisibility(this.mImage3InfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mImage3ImageContainer, View.VISIBLE);
                UIUtils.setVisibility(this.mCreativityAdInfoLayout, View.VISIBLE);
                break;
            }
            case 4: {
                UIUtils.setVisibility(this.mImage3InfoLayout, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdLayout, View.GONE);
                UIUtils.setVisibility(this.mRightImageAdLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageLayout, View.GONE);
                UIUtils.setVisibility(this.mLargeImageAdInfoLayout_AdInfoLayout, View.GONE);
                UIUtils.setVisibility(this.mRightInfoLayoutGroup, View.VISIBLE);
                UIUtils.setVisibility(this.mRightImageAdCreativityLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mCreativityAdInfoLayout, View.VISIBLE);
                UIUtils.setVisibility(this.mImage3ImageContainer, View.GONE);
                break;
            }
        }
    }
}

